﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Business {
    /// <summary>
    /// class for user input validation
    /// </summary>
    public class Validation {
        /// <summary>
        /// Checks for empty input.
        /// </summary>
        /// <param name="textvalue">The textvalue.</param>
        /// <returns>
        ///     <c>false</c> if the input is null or empty; otherwise, <c>false</c>.
        /// </returns>
        public bool CheckEmpty(string textvalue) {
            if (string.IsNullOrEmpty(textvalue)) {
                return false;
            }
            return true;
        }
        /// <summary>
        /// Checks the alpha numeric.
        /// </summary>
        /// <param name="textValue">The text value.</param>
        /// <returns>
        ///     <c>false</c> if the input is not letter or number; otherwise, <c>false</c>.
        /// </returns>
        public bool CheckAlphaNum(string textValue) {
            for (int i = 0; i < textValue.Length; i++) {
                if (!(char.IsLetter(textValue[i])) && (!(char.IsNumber(textValue[i]))))
                    return false;
            }
            return true;
        }
        /// <summary>
        /// Checks the alpha.
        /// </summary>
        /// <param name="textValue">The text value.</param>
        /// <returns>
        ///     <c>false</c> if the input is not letter; otherwise, <c>false</c>.
        /// </returns>
        public bool CheckAlpha(string textValue) {
            for (int i = 0; i < textValue.Length; i++) {
                if (!(char.IsLetter(textValue[i])))
                    return false;
            }
            return true;
        }
        /// <summary>
        /// Checks the num.
        /// </summary>
        /// <param name="textValue">The text value.</param>
        /// <returns>
        ///     <c>false</c> if the input is not number; otherwise, <c>false</c>.
        /// </returns>
        public bool CheckNum(string textValue) {
            for (int i = 0; i < textValue.Length; i++) {
                if (!(char.IsNumber(textValue[i])))
                    return false;
            }
            return true;
        }
        /// <summary>
        /// Checks the date.
        /// </summary>
        /// <param name="dateValue">The date value.</param>
        /// <returns>
        ///     <c>false</c> if the input is not in date format; otherwise, <c>false</c>.
        /// </returns>
        public bool CheckDate(string dateValue) {
            DateTime d;
            try {
                d = DateTime.Parse(dateValue);
            } catch {
                return false;
            }
            return true;
        }
    }
}
